#include <stdio.h>
#include <string.h>
#define MAX_ONE_LINE_LENGTH 100
#define MAX_CMD_LENGTH      20
#define DEBUG_SHOW

char **split(char *cmdLine,int Len,char ret2user[][MAX_CMD_LENGTH],char *retLen){
    char src[MAX_ONE_LINE_LENGTH],*ret[MAX_ONE_LINE_LENGTH];
    char *ptr=src;
    unsigned int count=0,i=0;
    char preChar=' ';
    strcpy(src,cmdLine);
    while(*ptr!='\0'){
        if((*ptr!=' ')&&preChar==' '){
            preChar = *ptr;
            ret[count++] = ptr;
        }
        else if(*ptr==' '&&preChar!=' '){
            preChar = *ptr;
            *ptr='\0';
            strcpy(ret2user[count-1],ret[count-1]);
        }
        ptr++;
    }
    strcpy(ret2user[count-1],ret[count-1]);
    *retLen = count;
}

int main(int argc, char* argv[]){
    char *src1="faf ffdsg  gsg sg sgg  fs g  gsg";
    char *src2="  vs faf ffdsg  gsg sg sgg  fs g  gsg    ";
    char ret[20][MAX_CMD_LENGTH]={"123","456","789"};
    char retlen;
    char cmdLine[100];
    int i=0;
    memset(cmdLine,0,100);
    for(i=1;i<argc;i++){
        strcat(cmdLine,argv[i]);
        strcat(cmdLine," ");
    }
    printf("%s\r\n",cmdLine);
    split(cmdLine,strlen(cmdLine),ret,&retlen);
    for(i=0;i<retlen;i++){
        printf("%d : %s\r\n",i,ret[i]);
    }
    return 0;
}

